package com.longnows.appserver.service.impl;

import com.longnows.appserver.model.Category;
import com.longnows.appserver.repository.CategoryRepository;
import com.longnows.appserver.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;

    public  Map<Integer,List<Category>> getAll(){
        List<Category> roots = categoryRepository.findAllByIsRootOrderByIndexAsc(true);
        List<Category> subs = categoryRepository.findAllByIsRootOrderByIndexAsc(false);
        Map<Integer,List<Category>> categories= new HashMap<>();
        categories.put(1,roots);
        categories.put(2,subs);
        return categories;
    }

}
